package com.shaco.heroproject.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.shaco.heroproject.R;
import com.shaco.heroproject.adapter.EquipmentListAdapter;
import com.shaco.heroproject.adapter.EquipmentListGoodAdapter;
import com.shaco.heroproject.entity.JsonAR;


/**
 * Created by dllo on 15/11/2.
 */
public class EquipmentListActivity extends Activity implements View.OnClickListener {
    private RecyclerView recyclerView;
    private EquipmentListAdapter equipmentListAdapter;
    private EquipmentListGoodAdapter equipmentListGoodAdapter, equipmentListGoodAdapter1, equipmentListGoodAdapter2, equipmentListGoodAdapter3;
    private Button activity_equipment_backBtn;
    private JsonAR jr;
    private TextView equipment_leixingTv, equipment_titleTv, equipment_timeTv,
            equipment_authorTv, equipment_serverTv, equipment_numberTv,
            equipment_pre_explainTv, equipment_mid_explainTv, equipment_end_explainTv,
            equipment_nf_explainTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_equipment_list);
        initView();
        initData();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.activity_equipment_backBtn:
                finish();
                break;
        }
    }

    private void initView() {
        jr = (JsonAR) getIntent().getSerializableExtra(HeroInforEquipmentActivity.SER_KEY);
        Log.i("shaco", "jr" + jr);

        activity_equipment_backBtn = (Button) findViewById(R.id.activity_equipment_backBtn);
        activity_equipment_backBtn.setOnClickListener(this);

//        equipment_skillIv

        equipment_leixingTv = (TextView) findViewById(R.id.equipment_leixingTv);
        equipment_leixingTv.setText("[" + jr.getGame_type() + "]");
        equipment_titleTv = (TextView) findViewById(R.id.equipment_titleTv);
        equipment_titleTv.setText(jr.getTitle());
        equipment_timeTv = (TextView) findViewById(R.id.equipment_timeTv);
        equipment_timeTv.setText(jr.getTime());
        equipment_authorTv = (TextView) findViewById(R.id.equipment_authorTv);
        equipment_authorTv.setText("作者:" + jr.getAuthor());
        equipment_serverTv = (TextView) findViewById(R.id.equipment_serverTv);
        equipment_serverTv.setText(jr.getServer());
        equipment_numberTv = (TextView) findViewById(R.id.equipment_numberTv);
        equipment_numberTv.setText("战斗力:" + jr.getCost_nf());
        equipment_pre_explainTv = (TextView) findViewById(R.id.equipment_pre_explainTv);
        equipment_pre_explainTv.setText(jr.getPre_explain());
        equipment_mid_explainTv = (TextView) findViewById(R.id.equipment_mid_explainTv);
        equipment_mid_explainTv.setText(jr.getMid_explain());
        equipment_end_explainTv = (TextView) findViewById(R.id.equipment_end_explainTv);
        equipment_end_explainTv.setText(jr.getEnd_explain());
        equipment_nf_explainTv = (TextView) findViewById(R.id.equipment_nf_explainTv);
        equipment_nf_explainTv.setText(jr.getNf_explain());


//        equipment_skillIv = (ImageView) findViewById(R.id.equipment_skillIv);


        recyclerView = (RecyclerView) findViewById(R.id.equipment_heroSkillRecyclerView);
        // 给RecyclerView设置布局管理器
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 6);

        recyclerView.setLayoutManager(gridLayoutManager);
        // 初始化适配器对象
        equipmentListAdapter = new EquipmentListAdapter(this);
        // 绑定适配器
        recyclerView.setAdapter(equipmentListAdapter);

        //---------出门装---------//

        recyclerView = (RecyclerView) findViewById(R.id.equipment_heroBeginRecyclerView);
        // 给RecyclerView设置布局管理器
        GridLayoutManager gridLayoutManager1 = new GridLayoutManager(this, 6);

        recyclerView.setLayoutManager(gridLayoutManager1);
        // 初始化适配器对象
        equipmentListGoodAdapter = new EquipmentListGoodAdapter(this);
        // 绑定适配器
        recyclerView.setAdapter(equipmentListGoodAdapter);

        //---------中期---------//
        recyclerView = (RecyclerView) findViewById(R.id.equipment_heroMidRecyclerView);
        // 给RecyclerView设置布局管理器
        GridLayoutManager gridLayoutManager2 = new GridLayoutManager(this, 6);

        recyclerView.setLayoutManager(gridLayoutManager2);
        // 初始化适配器对象
        equipmentListGoodAdapter1 = new EquipmentListGoodAdapter(this);
        // 绑定适配器
        recyclerView.setAdapter(equipmentListGoodAdapter1);

        //---------顺风出装---------//
        recyclerView = (RecyclerView) findViewById(R.id.equipment_heroSFRecyclerView);
        // 给RecyclerView设置布局管理器
        GridLayoutManager gridLayoutManager3 = new GridLayoutManager(this, 6);

        recyclerView.setLayoutManager(gridLayoutManager3);
        // 初始化适配器对象
        equipmentListGoodAdapter2 = new EquipmentListGoodAdapter(this);
        // 绑定适配器
        recyclerView.setAdapter(equipmentListGoodAdapter2);


        //---------逆风出装---------//
        recyclerView = (RecyclerView) findViewById(R.id.equipment_heroNFRecyclerView);
        // 给RecyclerView设置布局管理器
        GridLayoutManager gridLayoutManager4 = new GridLayoutManager(this, 6);

        recyclerView.setLayoutManager(gridLayoutManager4);
        // 初始化适配器对象
        equipmentListGoodAdapter3 = new EquipmentListGoodAdapter(this);
        // 绑定适配器
        recyclerView.setAdapter(equipmentListGoodAdapter3);


    }

    private void initData() {
        //技能部分
        String[] skills = jr.getSkill().split(",");

        String name = jr.getEn_name();
        Log.i("shaco", skills[1] + "+++++" + skills.length + "-----" + name);

        equipmentListAdapter.addData(skills, name);


//        for (int i = 0; i <skills.length ; i++) {
//
//            Log.i("shaco","------"+skills[i]);
//
//        }
        //出门装
        String[] pre_czs = jr.getPre_cz().split(",");
        Log.i("shaco", pre_czs[0] + "+++++" + pre_czs.length + "-----");

        equipmentListGoodAdapter.addData(pre_czs);

        //中期出装
        String[] mid_czs = jr.getMid_cz().split(",");
        equipmentListGoodAdapter1.addData(mid_czs);
        //顺风出装
        String[] end_czs = jr.getEnd_cz().split(",");
        equipmentListGoodAdapter2.addData(end_czs);
        //逆风出装
        String[] nf_czs = jr.getNf_cz().split(",");
        equipmentListGoodAdapter3.addData(nf_czs);


    }

}
